package com.example.Dao;

import com.example.entity.Goods;
import com.example.entity.Orderdetail;
import com.example.entity.Orders;
import com.example.entity.Users;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

@Mapper
public interface OrderdetailDao {
    @Results({
            @Result(column = "gdID",property = "goods",javaType = GoodsDao.class,
                    one = @One(select = "com.example.Dao.GoodsDao.findById"))
    })
    @Select("select * from orderdetail")
    ArrayList<Orderdetail> queryAll();


    @Select("select * from orderdetail where oid = #{oid}")
    @Results({
            @Result(column = "gdID",property = "goods",javaType = GoodsDao.class,
                    one = @One(select = "com.example.Dao.GoodsDao.findById"))
    })
    ArrayList<Orderdetail> query(Integer oid);

    @Delete("delete from orderdetail where odID = #{id}")
    int deleteByID(Integer id);

    @Results({
            @Result(column = "gdID",property = "goods",javaType = GoodsDao.class,
                    one = @One(select = "com.example.Dao.GoodsDao.findById"))
    })
    @Select("select * from orderdetail where odID = #{id}")
    Orderdetail findById(Integer id);

    @Update("UPDATE orderdetail SET " +
            "odNum = #{orderdetail.odnum}," +
            "dEvalution = #{orderdetail.devalution}" +
            "WHERE odID =  #{orderdetail.odid}")
    int update(@Param("orderdetail") Orderdetail orderdetail);

    @Insert("INSERT INTO orderdetail" +
            "(oID,gdID,odNum,dEvalution)" +
            "VALUES(#{orderdetail.oid},#{orderdetail.gdid},#{orderdetail.odnum},#{orderdetail.devalution})")
    int insert(@Param("orderdetail") Orderdetail orderdetail);
}
